home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2843 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.5 KB  |  62 lines

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Classes in DLL's
  5. Date: Sat, 20 Jan 1996 00:47:35 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4dpe2g$63d@news.halcyon.com>
  8. References: <4dotif$1dkc@rtpnews.raleigh.ibm.com>
  9. NNTP-Posting-Host: blv-pm10-ip8.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. jtoering@vnet.ibm.com wrote:
  13.  
  14. >I am familiar with how to import functions from
  15. >DLL's but how do you import class methods?
  16.  
  17. >thanks
  18.  
  19. >Jim T
  20.  
  21. Generally, use an import library.  
  22. Don't expect DLLs and EXEs made by different compilers to name-mangle
  23. identically; a DLL made with Borland C++ may not dynalink well to a
  24. MSVC executable.  
  25.  
  26. GetProcAddress() on class methods is problematic; you need to know the
  27. 'decorated' (mangled) name, you're pretty much restricted to static
  28. methods, etc.  You can still late-bind to the DLL, however, by using
  29. GetProcAddress() on a 'C' style function that returns a pointer to an
  30. object instance.  Then use the pointer like you would any other.
  31.  
  32. Then there's COM, the Ole-style interfaces.
  33.  
  34. Hope this helps.
  35.                     --Norm
  36.  
  37. ///////////////////////
  38. mydll.h
  39. #define   EXPORT  __declspec(dllexport)
  40. class myclass
  41. {
  42.     EXPORT myclass();
  43.     EXPORT virtual ~myclass();
  44.     EXPORT virtual  save( CArchive & archive ) const;
  45.     ...
  46. };
  47.     // for late-binding fans...
  48. extern "C" EXPORT myclass *   CreateInstance( void );
  49.  
  50. mydll.mak
  51. /IMPLIB:mydll.lib            ; for early-binding fans
  52.  
  53. myexe.cpp
  54. #include<mydll.h>
  55. ...
  56.  
  57. myexe.mak
  58. /LIB: mydll.lib
  59.  
  60.  
  61.  
  62.